#ifndef GRAPHICSSCENE_H
#define GRAPHICSSCENE_H

#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsItem>
#include "FigureContainer.h"

class GraphicsScene : public QGraphicsScene
{

    Q_OBJECT

public:
    explicit GraphicsScene(QObject *parent = 0);
    ~GraphicsScene();
    bool readFile(QString& fileName);
    bool writeFile(QString& fileName);
    void drowFigures(size_t num);
    void clearPicture();

private:
    void saveNewScale();
    void mousePressEvent(QGraphicsSceneMouseEvent * event);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);

public slots:
    void slotRotationValue(int value);
    void slotExtansionValue(int value);
    void slotRectangleMode();
    void slotCircleMode();
    void slotTriangleMode();
    void slotDrowMode();
    void slotSelectMode();
    void slotActionMode();
    void slotShiftMode();
    void slotRotationMode();
    void slotExtensionMode();

signals:
    void signalActionMode(int numSelectedFigures);
    void signalShiftPress();
    void signalShiftRelease();

private:
    FigureContainer figureContainer;
    QMap<QGraphicsItem*, size_t> interpreterMap;
    QVector<size_t> curentSelectedFiguresNum;
    QList<QGraphicsItem*> curentSelectedFiguresItems;
    QGraphicsItem* figureItem = nullptr;
    QGraphicsPolygonItem* dashItem;
    QGraphicsLineItem* lineItem = nullptr;
    QPoint centrePoint;
    int R;
    int a;
    int b;

    double newScale;
    bool scaleChanged = false;

    bool rectangleModeFlag;
    bool circleModeFlag;
    bool triangleModeFlag;

    bool drowModeFlag = true;
    bool selectModeFlag = false;

    bool shiftModeFlag = false;

    QPolygon trianglePolygon;

    QPolygonF selectionArea;
};

#endif // GRAPHICSSCENE_H
